import React,{Component} from "react";


class exercise extends Component{
    state={
        form:{
            title:'',
            conter:''
        },
        list:[
            {
                title:'我去取钱',
                conter:'钱没了'
            }
        ]
    }
    handtitle=(e)=>{
        Object.defineProperty(this.state.form,'title',{value:e.target.value})
        this.setState({
            form:this.state.form
        })
        console.log(e);
    }

    handconter=(e)=>{
        Object.defineProperty(this.state.form,'conter',{value:e.target.value})
        this.setState({
            form:this.state.conter
        })
        console.log(e.target.value);
    }

    render(){
        return(<>
        <h2>练习</h2>
        标题
        <input type="text" value={this.state.form.title}  onChange={this.handtitle}/>
        内容
        <input type="text" value={this.state.form.conter}  onChange={this.handconter}/>
        <button>发布</button>
        <ul>
            {
                this.state.list.map((item,index)=><li key={index}>
                <h2>标题</h2>
                <span>{item.title}</span>
                <h2>内容</h2>
                <span>{item.conter}</span>
                <button onClick={()=>this.handtitle(index)}>删除</button>
                </li>
                )
            }
        </ul>
        </>
        )
    }

}



export default exercise
